package org.example.backend.controller;

import org.example.backend.model.GameScore;
import org.example.backend.repository.GameScoreRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/api/game")
@CrossOrigin
public class GameController {
    
    private static final Logger logger = LoggerFactory.getLogger(GameController.class);
    
    @Autowired
    private GameScoreRepository gameScoreRepository;
    
    @PostMapping("/score")
    public GameScore saveScore(@RequestBody GameScore gameScore) {
        gameScore.setPlayTime(LocalDateTime.now());
        return gameScoreRepository.save(gameScore);
    }
    
    @GetMapping("/highscores")
    public List<GameScore> getHighScores() {
        List<GameScore> scores = gameScoreRepository.findTop10ByOrderByScoreDesc();
//        logger.info("Found {} scores", scores.size());
        return scores;
    }
} 